package com.hnevc.yourhealthmanager.controller;

import com.hnevc.yourhealthmanager.dto.ResponseResult;
import com.hnevc.yourhealthmanager.dto.SportRecordDTO;
import com.hnevc.yourhealthmanager.dto.WeightRecordDTO;
import com.hnevc.yourhealthmanager.entity.HealthPlane;
import com.hnevc.yourhealthmanager.entity.WeightRecord;
import com.hnevc.yourhealthmanager.service.WeightRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/WeightRecord")
@Api(tags = "收获体重记录数据接口")
public class WeightRecordController {
    @Autowired
    private WeightRecordService weightRecordService;

    @PostMapping("/add")
    @ApiOperation(value = "addWeightRecord", notes = "添加体重记录数据信息，跑步，步行，篮球等")
    public ResponseResult addWeightRecord(@RequestBody WeightRecord weightRecord) {
        weightRecordService.save(weightRecord);
        return ResponseResult.success(weightRecord);
    }

    @PostMapping("/{id}")
    @ApiOperation(value = "getWeightRecordById", notes = "获取体重记录数据信息等")
    public ResponseResult getWeightRecordById(@PathVariable Integer id) {
        WeightRecord categoryServiceById = weightRecordService.getById(id);
        return ResponseResult.success(categoryServiceById);
    }
    @GetMapping("/list")
    @ApiOperation(value = "listWeightRecord", notes = "获取所有体重记录数据列表信息")
    public ResponseResult listWeightRecord() {
        List<WeightRecord> addresses = weightRecordService.list();
        return ResponseResult.success(addresses);
    }
    @PutMapping("/update")
    @ApiOperation(value = "updateWeightRecord", notes = "更新体重记录数据信息")
    public ResponseResult updateWeightRecord(@RequestBody WeightRecord weightRecord) {
        weightRecordService.updateById(weightRecord);
        return ResponseResult.success(weightRecord);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "deleteWeightRecord", notes = "根据ID删除体重记录数据信息")
    public ResponseResult deleteWeightRecord(@PathVariable Integer id) {
        weightRecordService.removeById(id);
        return ResponseResult.success(null);
    }
    @GetMapping("/listByUserId/{userId}")
    @ApiOperation(value = "getWeightRecordListByUserId", notes = "根据用户ID获取饮食全部列表")
    public ResponseResult getWeightRecordListByUserId(@PathVariable Integer userId) {
        List<WeightRecordDTO> weightRecordDTOS = weightRecordService.getWeightRecordListByUserId(userId);
        return ResponseResult.success(weightRecordDTOS);
    }

    @PostMapping("/listByHealthPlane")
    @ApiOperation(value = "getWeightRecordListByUserId", notes = "根据指定计划饮食全部列表")
    public ResponseResult getWeightRecordListByUserId( @RequestBody HealthPlane healthPlane) {
        List<WeightRecordDTO> weightRecordDTOS = weightRecordService.getWeightRecordListByHealthPlane(healthPlane);
        return ResponseResult.success(weightRecordDTOS);
    }
    @PostMapping("/listByHealthPlaneMont/{year}/{month}")
    @ApiOperation(value = "getWeightRecordListByPlaneMonth", notes = "根据指定计划饮食，和月份列表")
    public ResponseResult getWeightRecordListByPlaneMonth( @RequestBody HealthPlane healthPlane, @PathVariable("year") Integer year, @PathVariable("month") Integer month) {
        List<WeightRecordDTO> weightRecordDTOS = weightRecordService.getWeightRecordListByPlaneMonth(healthPlane,month,year);
        return ResponseResult.success(weightRecordDTOS);
    }
}
